import CryptoJS from 'crypto-js';

const key = 'MY12345678902023';
const keyHex = CryptoJS.enc.Utf8.parse(key);

export const decrypt = (encryptedData) => {
  try {
    const decrypted = CryptoJS.AES.decrypt(encryptedData, keyHex, {
      mode: CryptoJS.mode.ECB,
      padding: CryptoJS.pad.Pkcs7
    });
    
    return decrypted.toString(CryptoJS.enc.Utf8);
  } catch (error) {
    console.error('解密失败:', error);
    return '';
  }
};

export const encrypt = (data) => {
  try {
    const encrypted = CryptoJS.AES.encrypt(data, keyHex, {
      mode: CryptoJS.mode.ECB,
      padding: CryptoJS.pad.Pkcs7
    });
    
    return encrypted.toString();
  } catch (error) {
    console.error('加密失败:', error);
    return '';
  }
}; 